<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="flag = 0">默认</button>
        <button @click="flag = 1">升序</button>
        <button @click="flag = 2">降序</button>
        <p><input type="text" v-model="scrach">输入搜索</p>
        <p v-for="item in changeList" :key="item.id">姓名：{{item.name}} --年龄: {{item.age}}</p>
    </div>
    <script>
        const vm = new Vue({
            data() {
                return {
                    scrach: "",
                    goodList: [
                        { id: "001", name: "周杰伦", age: "18" },
                        { id: "002", name: "周迅", age: "22" },
                        { id: "003", name: "陈伟霆", age: "43" },
                        { id: "004", name: "陈冠希", age: "23" },
                        { id: "005", name: "杨幸", age: "26" },
                        { id: "006", name: "杨癫疯", age: "12" },
                        { id: "007", name: "李子园", age: "55" },
                        { id: "008", name: "李杰", age: "25" }
                    ],
                    flag: 0
                }
            },
            computed: {
                changeList() {
                    // const filterList = this.goodList.filter(item => item.name.includes(this.scrach));
                    if (this.flag === 0) {
                        return this.goodList.filter(item => item.name.includes(this.scrach))
                    } else if (this.flag === 1) {
                        return this.goodList.filter(item => item.name.includes(this.scrach)).sort((a, b) => a.age - b.age)
                    } else {
                        return this.goodList.filter(item => item.name.includes(this.scrach)).sort((a, b) => b.age - a.age)
                    }
                }
            }
        }).$mount("#app")
    </script>
</body>

</html>: